package socket.demo2;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;

public class Client {

    public static void main(String[] args) throws Exception {
        String msg = "什码情况 ^_^ ...";

        Socket socket = new Socket("127.0.0.1", 8080);
        PrintWriter writer = new PrintWriter(socket.getOutputStream());
        writer.println(msg);
        writer.flush();

        BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
        String line = reader.readLine();
        System.out.println("received from server: " + line);

        reader.close();
        writer.close();

        socket.close();
    }
}
